package com.jiawa.train.business.controller.admin;

import com.jiawa.train.business.req.DailyTrainQueryReq;
import com.jiawa.train.business.req.DailyTrainSaveReq;
import com.jiawa.train.business.service.DailyTrainService;
import com.jiawa.train.common.resp.PageResult;
import com.jiawa.train.common.resp.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/admin/dailyTrain")
@Slf4j
public class DailyTrainAdminController {

    @Resource
    private DailyTrainService dailyTrainService;
    @PostMapping("/save")
    public Result save(@RequestBody @Valid DailyTrainSaveReq req) {
        dailyTrainService.save(req);
        return Result.success();
    }
    @GetMapping("/page")
    public Result<PageResult> queryDailyTrainList(DailyTrainQueryReq  req) {
       PageResult pageResult = dailyTrainService.queryDailyTrainList(req);
       return Result.success(pageResult);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        dailyTrainService.delete(id);
        return Result.success();
    }

    @GetMapping("/genDaily/{date}")
    public Result genDaily(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        dailyTrainService.genDaily(date);
        return Result.success();
    }
}

